]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shell-util: Fix a memory leak of a floating variant on error
authorPhilip Withnall <pwithnall@gnome.org>
Fri, 28 Jun 2024 16:06:31 +0000 (17:06 +0100)
committerPhilip Withnall <pwithnall@gnome.org>
Fri, 28 Jun 2024 16:06:31 +0000 (17:06 +0100)
If `params` is floating when provided by the caller, and if one of the
early return paths is taken from this function, the call into GIO never
sinks and takes ownership of the `GVariant`, and hence it’s leaked.

Always explicitly sink the input variant as soon as the function is
called, then it can’t be leaked.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3396>

src/shell-util.c

index 742aa829a83e6a8f3685f5503745066484e40f42..a965c7148acb7084d2ff72a99352a40f4dd45241 100644 (file)
@@ -619,6 +619,7 @@ shell_util_systemd_call (const char           *command,
                          gpointer              user_data)
 {
   g_autoptr (GTask) task = g_task_new (NULL, cancellable, callback, user_data);
+  g_autoptr (GVariant) params_owned = g_variant_ref_sink (g_steal_pointer (&params));
 
 #ifdef HAVE_SYSTEMD
   g_autoptr (GDBusConnection) connection = NULL;
@@ -695,7 +696,7 @@ shell_util_systemd_call (const char           *command,
                           "/org/freedesktop/systemd1",
                           "org.freedesktop.systemd1.Manager",
                           command,
-                          params,
+                          params_owned,
                           G_VARIANT_TYPE ("(o)"),
                           G_DBUS_CALL_FLAGS_NONE,
                           -1, cancellable,